import UIKit

protocol SelectableButton: UIButton {
  func onTapped()
  func resetToDefault()
}

class SortButtonManager {

  private var buttons: [SelectableButton] = []

  func addButton(_ button: SelectableButton) {
    buttons.append(button)
    //        button.manager = self
    if let sortButton = button as? SortButton {
      sortButton.manager = self
    } else if let selectButton = button as? SelectButton {
      selectButton.manager = self
    }
  }

  func buttonTapped(_ tappedButton: SelectableButton) {
    for button in buttons {
      if button == tappedButton {
        button.onTapped()
      } else {
        button.resetToDefault()
      }
    }
  }

  func resetAll() {
    for button in buttons {
      button.resetToDefault()
    }
  }
}
